/*
 * @lc app=leetcode.cn id=3 lang=java
 *
 * [3] 无重复字符的最长子串
 */

// @lc code=start
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int len = s.length();
        if(len == 0){
            return 0;
        }
        int[] count = new int[128];
        int l = 0, r = 0;
        int ans = 1;
        for(;r<len;r++){
            while(count[s.charAt(r)] != 0){
                count[s.charAt(l++)]--;
            }
            count[s.charAt(r)]++;
            ans = Math.max(ans, r - l + 1);
            
        }
        return ans;
    }
}
// @lc code=end

